import 'package:qgchat/http/io.dart';
import 'package:qgchat/http/models/LiveListModel.dart';

class LiveApis {
  /// 当前正在进行的直播列表
  static Future<List<LiveListModel>> liveList() {
    return Io.get('live/list').then<List<LiveListModel>>((res) {
      final arr = res['data'];
      return List<LiveListModel>.generate(
        arr.length,
        (index) => LiveListModel.fromJson(arr[index]),
      );
    });
  }

  /// 直播间信息
  static Future<LiveListModel> liveInfo(int id) {
    return Io.get('live/detail', data: {'id': id}).then<LiveListModel>((res) {
      return LiveListModel.fromJson(res['data']);
    });
  }

  /// 开启直播
  static Future<int> liveOpen(int aid, String name, String cover) {
    return Io.post(
      'live/open',
      data: {
        "aid": aid,
        "name": name,
        "cover": cover,
      },
    ).then((res) => res['data']['id']);
  }

  /// 直播结束
  static Future liveClose(int id) {
    return Io.post('live/close', data: {'id': id});
  }
}
